package oracle.springbootxm.dao.goodsdao;

import oracle.springbootxm.pojo.GoodsInfo;
import oracle.springbootxm.pojo.UserGoodsInfo;
import oracle.springbootxm.pojo.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface GoodsMapper {
    @Select("select goodsid,goodsname,goodspic,goodscount,goodsdesc,goodsprice from fruitgoods")
    @Results({
            @Result(property = "goodsid", column = "goodsid"),
            @Result(property = "goodsname", column = "goodsname"),
            @Result(property = "goodspic", column = "goodspic"),
            @Result(property = "goodscount", column = "goodscount"),
            @Result(property = "goodsdesc", column = "goodsdesc"),
            @Result(property = "goodsprice", column = "goodsprice")
    })
    List<GoodsInfo> queryGoodsInfoAll();

    @Insert("insert into usergoods(userid,goodsid,usergoodscount) values(#{userid},#{goodsid},#{usergoodscount})")
    @Results({
            @Result(property = "userid", column = "userid"),
            @Result(property = "goodsid", column = "goodsid"),
            @Result(property = "usergoodscount", column = "usergoodscount")
    })
    void addGoods(Map map);

    @Select("select userid,goodsid,usergoodscount from usergoods where userid = #{userid} and goodsid = #{goodsid}")
    UserGoodsInfo queryuserGoods(int userid, int goodsid);

    @Update("update usergoods set usergoodscount = #{countsum} where goodsid = #{goodsid}")
    void updateCount(int countsum, int goodsid);

    @Select("select goodsname,goodsid,goodspic,goodscount,goodsdesc,goodsprice from fruitgoods where goodsid = #{goodsid}")
    GoodsInfo queryshowGoods(int goodsid);

    @Select("select goodsid from usergoods where userid = #{userid}")
    GoodsInfo queryshowGoodsid(int userid);

    @Select("select userid,goodsid,usergoodscount from usergoods where userid = #{userid}")
    List<UserGoodsInfo> queryuserAllGoods(int userid);

    @Delete("delete from usergoods where userid = #{userid} and goodsid = #{goodsid}")
    void deleteGoods(int userid, int goodsid);

    @Delete("delete from fruitgoods where goodsid = #{goodsid}")
    void deleteStoreGoods(int goodsid);

    @Insert("insert into testgoods(goodsname,goodspic,goodscount,goodsdesc,goodsprice) values(#{goodsname},#{goodspic},#{goodscount},#{goodsdesc},#{goodsprice})")
    void addNewGoods(GoodsInfo goodsInfo);

    @Select("select goodsname,goodsid,goodspic,goodscount,goodsdesc,goodsprice from fruitgoods where goodsname = #{goodsname}")
    GoodsInfo querynewGoods(String goodsname);
}
